package cn.wolfcode.luowowo.redis;

import cn.wolfcode.luowowo.util.Consts;
import lombok.Data;
import lombok.Getter;

/**
 * 枚举类 用于添加唯一的属性方法等
 */
@Getter
public enum RedisKey {
    //定义一个实例方法 时间设置为秒的类型
    USER_ACCESS_DAY("user_access_day",-1),
    USER_ACCESS_KEY("user_access_key",-1),
    //用来判断是否顶了的key前缀
    USER_STRATEGY_THUMBSUPNUM_KEY("user_strategy_key",-1),
    //用户收藏的key
    USER_COLLECT_KEY("user_collect_key", -1),
    //验证kye
    VERIFY_CODE("VerifyCode", Consts.VERIFY_CODE_VAI_TIME * 60),
    //统计数据的key,
    STRATEGY_STATIS_KEY("strategy_statis_key", -1),
    //登录的key
    USER_KEY("USER_KEY",Consts.USER_INFO_TOKEN_VAI_TIME *60);
    
    private String prefix;  //前缀
    private int time;    //存在时间
    
    private RedisKey(String prefix,int time){
        this.prefix = prefix;
        this.time = time;
    }
    
    //定义一个方法拼接key
    public String join(String...key){
        //拼接字段的长度
        StringBuilder builder = new StringBuilder(100);
        builder.append(this.prefix);
        //循环添加
        for (String s : key) {
            builder.append(":").append(s);
        }
        //返回拼接后的长度
        return builder.toString();
    }
}
